#include <iostream>
using namespace std;

typedef char DataType;

//二叉树数据结构
struct node
{
    DataType info; //存放结点数据
    struct node *lchild, *rchild; //指向左右孩子的指针
};

typedef struct node *BiTree;

/*创建二叉树
  函数名：createBiTree
  参数：无
  返回值：二叉树根结点指针
  */
BiTree createBiTree(void)
{
    char ch;
    BiTree  root;
    cin >> ch;
    if (ch == '#') root = NULL;
    else {
        root = new struct node;
        root->info = ch;
        root->lchild = createBiTree();
        root->rchild = createBiTree();
    }
    return root;
}

void visit(BiTree T)
{
    cout << T->info;
}

int countLeaf(BiTree root)
{
    //请在此处填写代码， 计算二叉树中树叶的个数
    /********** Begin **********/
    int nodes;
    if (root == NULL)
    {
        return 0;
    }

    if (root->lchild == NULL || root->rchild == NULL)
        return 0;
    else if (root->lchild == NULL && root->rchild != NULL)
        nodes = countLeaf(root->lchild);
    else if (root->rchild == NULL && root->lchild != NULL)
        nodes = countLeaf(root->rchild);
    else
        nodes = 1 + countLeaf(root->lchild) + countLeaf(root->rchild);//加一是因为可以确定现在的那个root是个满结点。
    return nodes;
    /********** End **********/
}

int main(void)
{
    BiTree root = createBiTree();
    cout << countLeaf(root);
}
